<?php
$caption = BUtils::T('customers_lbl');
$this->pageTitle = $caption;

$this->breadcrumbs = array(
	$caption,
);

$last_7_days = date(BUtils::T('php_date_long'), mktime(0, 0, 0, date('m'), date('d')-7)) . ' - ' . date(BUtils::T('php_date_long'));
$last_28_days = date(BUtils::T('php_date_long'), mktime(0, 0, 0, date('m'), date('d')-28)) . ' - ' . date(BUtils::T('php_date_long'));
$today_date = date(BUtils::T('php_date_long'));
$yesterday_date = date(BUtils::T('php_date_long'), mktime(0, 0, 0, date('m'), date('d')-1));
?>
<div class="page-header position-relative">
	<div class="pull-right">
		<a class="btn btn-primary" href="<?php echo Yii::app()->createUrl('/points/to'); ?>">
			<i class="icon-credit-card bigger-120"></i>
			<?php echo BUtils::T('points_to_customer_lbl'); ?>
		</a>
		<a class="btn btn-success" href="<?php echo Yii::app()->createUrl('/points/from'); ?>">
			<i class="icon-trophy bigger-120"></i>
			<?php echo BUtils::T('points_from_customer_lbl'); ?>
		</a>
	</div>
	<h1>
		<?php echo $caption; ?>
	</h1>
</div><!--/.page-header-->

<div class="row-fluid">
	<!-- Message -->
	<!--
	<div class="alert alert-block alert-info">
		<button type="button" class="close" data-dismiss="alert">
			<i class="icon-remove"></i>
		</button>
		<i class="icon-info-sign"></i>
		Easy to know your customers.
	</div>
	-->
	
	<div class="space-6"></div>
	
	<div class="row-fluid">
		<div class="span6">
			<div class="btn-group">
				<button class="btn " data-toggle="dropdown" style="border-bottom-right-radius:4px;border-top-right-radius:4px;">
					<i class="icon-calendar"></i>
					<span id="customer-period-text"><?php echo BUtils::T('all_op_lbl'); ?></span>
					<span class="caret"></span>
				</button>
				<ul class="dropdown-menu dropdown-default" id="customer-period-list">
					<li>
						<a href="#all" data-name="all" data-value=""><?php echo BUtils::T('all_op_lbl'); ?></a>
					</li>
					<li>
						<a href="#today" data-name="today" data-value="<?php echo $today_date; ?>"><?php echo BUtils::T('today_lbl'); ?></a>
					</li>
					<li>
						<a href="#yesterday" data-name="yesterday" data-value="<?php echo $yesterday_date; ?>"><?php echo BUtils::T('yesterday_lbl'); ?></a>
					</li>
					<li>
						<a href="#last_7" data-name="last_7" data-value="<?php echo $last_7_days; ?>"><?php echo BUtils::T('last_num_days_lbl', array('{number}'=>7)); ?></a>
					</li>
					<li>
						<a href="#last_28" data-name="last_28" data-value="<?php echo $last_28_days; ?>"><?php echo BUtils::T('last_num_days_lbl', array('{number}'=>28)); ?></a>
					</li>
				</ul>
			</div>
			<span id="customer-period-date" style="margin-left:8px;"></span>
		</div>
		<div class="span6 text-right" style="padding-right:8px;">
<?php
echo CHtml::form(Yii::app()->createUrl($this->id.'/'.$this->action->id), 'get', array('id'=>'search_form', 'class'=>'form-inline')) . "\n";
echo CHtml::textField('q', '', array('class'=>'span4')) . "\n";
echo CHtml::ajaxButton(BUtils::T('search_btn'), null, array('type'=>'get', 'beforeSend'=>'beforeSend', 'success'=>'success'), array('class'=>'btn btn-blue')) . "\n";
echo CHtml::endForm();
?>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span12">
			<div id="loading-bar" style="text-align:center; margin:20px 0;">
				<img src="<?php echo Yii::app()->baseUrl; ?>/img/ajax-loaders/ajax-loader-4.gif" />
			</div>
			<div id="customer-list"></div>
		</div><!-- span12 -->
	</div>
</div>
<script type="text/javascript">
$(function() {
	$.ajax({
		beforeSend:beforeSend, success:success,
		type:'GET', url:location.href, data:$('#search_form').serialize()
	});
	$('#customer-period-list li a').click(function(ev){
		var _this = $(this);
		$('#customer-period-text').html(_this.html());
		$('#customer-period-date').html(_this.data('value'));
		$.ajax({
			beforeSend:beforeSend, success:success,
			type:'GET', url:location.href, data:{name:_this.data('name')}
		});
		ev.preventDefault();
	});
});
function beforeSend() {
	$('.btn-search').removeClass('active');
	$("#loading-bar").show();
	$("#customer-list").html('');
}
function success(html) {
	$("#loading-bar").hide();
	$("#customer-list").html(html);
}
</script>